package com.example.shopping_mall.base;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.example.shopping_mall.MainActivity;
import com.example.shopping_mall.R;
import com.example.shopping_mall.adapter.BrandDetailAdapter;
import com.example.shopping_mall.adapter.RecommendMoreAdapter;
import com.example.shopping_mall.bean.BrandBean;
import com.example.shopping_mall.bean.BrandManager;
import com.example.shopping_mall.bean.BrandMiddleBean;
import com.example.shopping_mall.http.ShoppingRequest;
import com.example.shopping_mall.utils.ShoppingUtils;

import java.util.ArrayList;
import java.util.List;

//品牌更多
public class RecommendMoreActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getSimpleName();

    private ShoppingRequest sr;
    List<BrandManager> managerList;
    RecyclerView recyclerView;

    ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recommend_more);

        sr = new ShoppingUtils();
        initView();
    }

    private void initView() {
        recyclerView=findViewById(R.id.recommend_more_recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        managerList=new ArrayList<>();

        sr.requestPmsBrand(new ShoppingUtils.OnPmsBrandRequestListener() {
            @Override
            public void OnPmsBrandRequest(BrandManager[] brandManagers) {
                for (int i = 0; i < brandManagers.length; i++) {
                    BrandManager manager=new BrandManager();
                    manager.setName(brandManagers[i].getName());
                    manager.setLogo(brandManagers[i].getLogo());
                    manager.setBrandStory(brandManagers[i].getBrandStory());
                    managerList.add(manager);
                }
                RecommendMoreAdapter adapter=new RecommendMoreAdapter(RecommendMoreActivity.this,managerList);
                recyclerView.setAdapter(adapter);

                //条目的点击事件
                adapter.setMoreClickListener(new RecommendMoreAdapter.onMoreClickListener() {
                    @Override
                    public void onMoreClick(int position) {
                        Intent intent=new Intent(RecommendMoreActivity.this,RecommendMoreDetailActivity.class);
                        intent.putExtra("more_detail_id",position);
                        Log.d(TAG, "000000000000000000: " + position);
                        startActivity(intent);
                    }
                });
            }
        });

        //返回主页面
        imageView=findViewById(R.id.recommend_more_back);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(RecommendMoreActivity.this, MainActivity.class));
            }
        });
    }
}